package com.fenghongzhang.zhoukao2;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class MyListAdapter extends BaseAdapter{

        Context context;
        List<Food.DataBean> list;

    public MyListAdapter(Context context, List<Food.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int i) {
            return list.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }


    @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            viewHodler viewHodler = null;
            if (view == null){
                viewHodler = new viewHodler();
                view = LayoutInflater.from(context).inflate(R.layout.food_layout,null);
                viewHodler.iv = view.findViewById(R.id.iv);
                viewHodler.tv = view.findViewById(R.id.tv);
                view.setTag(viewHodler);
            }else{
                viewHodler = (MyListAdapter.viewHodler) view.getTag();
            }
            viewHodler.tv.setText(list.get(i).getTitle());

            return view;
        }
        class viewHodler{
            TextView tv;
            ImageView iv;
        }
}


